package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(value = "订单")
public class UserOrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation(value = "用户创建订单")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO ov = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(ov);
    }

    @GetMapping("historyOrders")
    @ApiOperation(value = "获取用户订历史订单")
    public Result historyOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(orderService.historyOrders(ordersPageQueryDTO));
    }


    @GetMapping("/orderDetail/{id}")
    @ApiOperation(value = "获取订单详情")
    public Result orderDetail(@PathVariable("id") Long id) {
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    @PostMapping("/repetition/{id}")
    @ApiOperation(value = "再来一单")
    public Result<OrderSubmitVO> moreOrder(@PathVariable("id") Long id) {
        orderService.moreOrder(id);
        return Result.success();
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation(value = "取消订单")
    public Result<OrderSubmitVO> cancelOrder(@PathVariable("id") Long id) {
        orderService.cancelOrder(id, Orders.CANCELLED);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    @ApiOperation(value = "催单")
    public Result reminder(@PathVariable("id") Long id) {
         orderService.reminder(id);
        return Result.success();
    }
}
